//
//  StatusRepostedView.m
//  CMJWeibo
//
//  Created by BH on 16/1/4.
//
//

#import "StatusRepostedView.h"
#import "StatusFrame.h"
#import "PhotosView.h"
#import "StatusModel.h"
#import "UserInfo.h"
#import "UIImage+MJ.h"
#import "UIView+MJ.h"
#import "CMJCommon.h"

@interface StatusRepostedView()
//昵称
@property(nonatomic,strong)UILabel *repostedName;
//正文
@property(nonatomic,strong)UILabel *repostedContent;
//配图
@property(nonatomic,strong)PhotosView *repostedPhotos;

@end

@implementation StatusRepostedView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        self.image = [UIImage resizableImage:@"timeline_retweet_background"];
        
        UILabel *nameLab = [[UILabel alloc] init];
        nameLab.font = NicknameFont;
        nameLab.textColor = Color(66, 101, 105);
        [self addSubview:nameLab];
        self.repostedName = nameLab;
        
        UILabel *contentLab = [[UILabel alloc] init];
        contentLab.font = ContentFont;
        contentLab.numberOfLines = 0;
        [self addSubview:contentLab];
        self.repostedContent = contentLab;
        
        PhotosView *photosV = [[PhotosView alloc] init];
        [self addSubview:photosV];
        self.repostedPhotos = photosV;
    }
    return self;
}

-(void)setRepostStatusF:(StatusFrame *)repostStatusF
{
    _repostStatusF = repostStatusF;
    
    // 控制转发微博整体的可见性
    StatusModel *model = repostStatusF.status.retweeted_status;
    if (model) {
        //有转发
        self.hidden = NO;
        self.frame = repostStatusF.repostViewF;
    }else{
        //没有转发
        self.hidden = YES;
        return;
    }
    
    [self setupData];
    
    [self setupFrame];
}

/**
 *  设置数据
 */
-(void)setupData
{
    self.repostedName.text = [NSString stringWithFormat:@"@%@",self.repostStatusF.status.retweeted_status.user.name];
    
    self.repostedContent.text = self.repostStatusF.status.retweeted_status.text;
    
    self.repostedPhotos.photosArr = self.repostStatusF.status.retweeted_status.pic_urls;
}

/**
 *  设置frame
 */
-(void)setupFrame
{
    self.frame = self.repostStatusF.repostViewF;
    
    self.repostedName.frame = self.repostStatusF.repostNameF;
    self.repostedContent.frame = self.repostStatusF.repostContentF;
    self.repostedPhotos.frame = self.repostStatusF.repostPhotosF;
}

@end
